Micron Document
Fox's Git Mirrors

Node / RFnexus / code.git / files / bitman.hh

Displaying Raw • Download

bitman.hh b9d074adcf257a4f403874af6aa07a246f111f1a (b9d074ad) Text, 681 B

/*
Bit manipulation of byte arrays

Copyright 2018 Ahmet Inan <inan@aicodix.de>
*/

#pragma once

namespace CODE {

void xor_be_bit(uint8_t *buf, int pos, bool val)
{
buf[pos/8] ^= val<<(7-pos%8);
}

void xor_le_bit(uint8_t *buf, int pos, bool val)
{
buf[pos/8] ^= val<<(pos%8);
}

void set_be_bit(uint8_t *buf, int pos, bool val)
{
buf[pos/8] = (~(1<<(7-pos%8))&buf[pos/8])|(val<<(7-pos%8));
}

void set_le_bit(uint8_t *buf, int pos, bool val)
{
buf[pos/8] = (~(1<<(pos%8))&buf[pos/8])|(val<<(pos%8));
}

bool get_be_bit(const uint8_t *buf, int pos)
{
return (buf[pos/8]>>(7-pos%8))&1;
}

bool get_le_bit(const uint8_t *buf, int pos)
{
return (buf[pos/8]>>(pos%8))&1;
}

}


Served by rngit 1.5.2 - Generated in 0.03s